import React, {useEffect,createContext,useState} from 'react';
import { Route, Switch } from 'react-router-dom'
import { Row, Col, Affix} from 'antd';
import List from '../../components/List/List';
import styles from './index.module.css';
import MyInput from '../../components/searchInput/input';
import {IndexMain} from '../../components/indexMain';
import User from "../../components/user"
import TweetDetail from "../../components/indexMain/tweetDetail";
import Favor from "../../components/favor";
import LikeList from "../../components/recommendList/likeList";
import LastList from "../../components/recommendList/lastList";
import SearchList from "../../components/search/search";

export const IndexContext = createContext({info:[],setInfo:()=>{}})
export default function Index (props) {
    const [info,setInfo]=useState([])
    useEffect(()=>{//路由跳转
      console.log("test")
    if(!localStorage.getItem('TOKEN'))
      props.history.replace('/login')
  },[])
    return (
      <div className={styles.content}>
        <div className={styles.row}>
          <Row >
            <Col span={7}>
              <MyInput isRadius={true} delay={1000} size={5}></MyInput>
              <Affix offsetTop={45}>
                <div>
                  <LikeList/>
                  <LastList/>
                </div>
              </Affix>
            </Col>
            <IndexContext.Provider value={{info,setInfo}}>
            <Col span={12} >
              <Switch>
                <Route exact path={"/index/search"} component={SearchList}></Route>
                <Route exact path={"/index/favor"} component={Favor}></Route>
                <Route exact path={"/index/mine"} component={User}></Route>
                {/*<Route exact path={"/index/:user"} component={User}></Route>*/}
                <Route exact path={"/index/detail/:shareId"} component={TweetDetail}></Route>
                <Route path={"/index"} component={IndexMain}></Route>
              </Switch>
            </Col>
            <Col span={5}><List info={info} /></Col>
            </IndexContext.Provider>
          </Row>
        </div>
        </div>
    )
}


